package com.ltkj.shop.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ltkj.common.log.annotation.Log;
import com.ltkj.common.log.enums.BusinessType;
import com.ltkj.common.security.annotation.RequiresPermissions;
import com.ltkj.shop.domain.ShopStore;
import com.ltkj.shop.service.IShopStoreService;
import com.ltkj.common.core.web.controller.BaseController;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.common.core.utils.poi.ExcelUtil;
import com.ltkj.common.core.web.page.TableDataInfo;

/**
 * 文创商店Controller
 * 
 * @author xupf
 * @date 2023-08-29
 */
@Api(tags = "文创商店")
@RestController
@RequestMapping("/store")
public class ShopStoreController extends BaseController
{
    @Autowired
    private IShopStoreService shopStoreService;

    /**
     * 查询文创商店列表
     */
    @ApiOperation("查询文创商店列表")
    @RequiresPermissions("shop:store:list")
    @GetMapping("/list")
    public TableDataInfo list(ShopStore shopStore)
    {
        startPage();
        List<ShopStore> list = shopStoreService.selectShopStoreList(shopStore);
        return getDataTable(list);
    }

    /**
     * 导出文创商店列表
     */
    @ApiOperation("导出文创商店列表")
    @RequiresPermissions("shop:store:export")
    @Log(title = "文创商店", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopStore shopStore)
    {
        List<ShopStore> list = shopStoreService.selectShopStoreList(shopStore);
        ExcelUtil<ShopStore> util = new ExcelUtil<ShopStore>(ShopStore.class);
        util.exportExcel(response, list, "文创商店数据");
    }

    /**
     * 获取文创商店详细信息
     */
    @ApiOperation("获取文创商店详细信息")
    @RequiresPermissions("shop:store:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shopStoreService.selectShopStoreById(id));
    }

    /**
     * 新增文创商店
     */
    @ApiOperation("新增文创商店")
    @RequiresPermissions("shop:store:add")
    @Log(title = "文创商店", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopStore shopStore)
    {
        return success(shopStoreService.insertShopStore(shopStore));
    }

    /**
     * 修改文创商店
     */
    @ApiOperation("修改文创商店")
    @RequiresPermissions("shop:store:edit")
    @Log(title = "文创商店", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopStore shopStore)
    {
        return toAjax(shopStoreService.updateShopStore(shopStore));
    }

    /**
     * 删除文创商店
     */
    @ApiOperation("删除文创商店")
    @RequiresPermissions("shop:store:remove")
    @Log(title = "文创商店", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long id)
    {
        if (shopStoreService.countGoodsByStoreId(id, null) > 0)
        {
            return warn("已有上架商品,不允许删除");
        }
        return toAjax(shopStoreService.deleteShopStoreById(id));
    }
}
